package com.nulldev.util.web.URLUtils.internal;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

import com.nulldev.util.data.Base64.Base64;

public class DataConnection extends URLConnection {
	public DataConnection(URL u) {
		super(u);
	}

	@Override
	public void connect() throws IOException {
		connected = true;
	}

	@Override
	public InputStream getInputStream() throws IOException {
		String data = url.toString();
		data = data.replaceFirst("^.*;base64,", "");
		final byte[] bytes = Base64.decodeBase64(data);
		return new ByteArrayInputStream(bytes);
	}
}
